<?php
require __DIR__ . '/../../vendor/autoload.php';

use Medoo\Medoo;
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>来养鸭游戏规则</title>
    <style>
        *{margin: 0;padding: 0}
        html body{
            height: 100%;
        }
        .content {padding:20px;}
        p.headline {margin-top:12px; margin-bottom:10px; font-size:16px;}
        p {font-size:14px; line-height:20px;}

    </style>
</head>

<body>

<div class="head">
    <img src="game_share/rule_head.png" style="width:100%;" />
</div>


<?php

$filter  = array();
/* 过滤关键字读取开始 */
$file = __DIR__ . '/../../.env';
if (file_exists($file)){
    $file_handle = fopen($file, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        $str = trim($line);
        if(empty($str)) continue;
        $arr = explode('=', trim($line));
        $filter[$arr[0]] = $arr[1] ?? '';
    }
    fclose($file_handle);
}
/* 过滤关键字读取结束   */
// var_dump($filter);
$env_config = $filter;
if(empty($env_config['DB_CONNECTION'])) {
    exit('请检查服务器配置');
}
$DB = new Medoo([
    'database_type' => $env_config['DB_CONNECTION'],
    'database_name' => $env_config['DB_DATABASE'],
    'server' => $env_config['DB_HOST'],
    'username' => $env_config['DB_USERNAME'],
    'password' => $env_config['DB_PASSWORD'],
    'charset' => 'utf8',
]);
$content = $DB->get('game_config', '*', ['name' => 'couponRule']);
?>


<div class="content">

<?php echo $content['val']; ?>

</div>





<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
    (function() {
        var ua = navigator.userAgent.toLowerCase();
        var t;

        var config = {
            scheme_IOS: 'sportlottery://',
            scheme_Adr: 'sportlottery://splash',
            open_url_Adr: 'http://www.baidu.com?type=1',
            download_url_Adr: 'http://www.baidu.com?type=2',
            timeout: 600
        };

        //wx环境
        if(ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_'){
            $('.wx').css('display','block');
            $('.browser').css('display','none')
        }

        function openclient(type) {
            var ua = window.navigator.userAgent.toLowerCase();
            var url = '';
            if (type == 1){
                url = config.open_url_Adr;
            }else if (type == 2){
                url = config.download_url_Adr;
            }
            if(ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_'){
                alert('请在浏览器打开');
            }else{
                var starttime = Date.now();
                var ifr = document.createElement('iframe');
                ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;
                ifr.style.display = 'none';
                document.body.appendChild(ifr);

                var t = setTimeout(function() {
                    var endtime = Date.now();
                    if((endtime - starttime) < (config.timeout + 200)) {
                        if(/iphone|ipad|ipod/.test(ua)) {
                            alert('ios系统暂不支持');
                            //window.location.href = config.download_url_IOS;
                        } else if(/android/.test(ua)) {
                            window.location.href = url;
                        } else {
                            alert('未识别的系统');
                        }
                    } else {
                        window.close();
                    }
                }, config.timeout);

                window.onblur = function() {
                    clearTimeout(t);
                }
            }

        }
        window.addEventListener("DOMContentLoaded", function() {
            document.getElementById('open').addEventListener('click', function () {
                openclient(1)
            }, true);
            document.getElementById('download').addEventListener('click', function () {
                openclient(2)
            }, true);
        }, true);
    })();

</script></body></html>
